import React,{useState,useEffect,useRef} from 'react'

export default function StaHooks(){
    let [state,change]=useState({
        num:0,
        msg:'使用state hooks'
    })
    // let inp=createRef()
    let inp=useRef()



    useEffect(()=>{
        inp.current.focus()
    },[])

    useEffect(()=>{
        console.log(state)
    },[state.num])
    
    return <div style={{border:'2px dashed yellow'}}>
        <p>-------使用hooks-----</p>
        <div>useState----{state.num}</div>
        <div>useState----{state.msg}</div>
        <button onClick={ev=>change({
            ...state,
            num:state.num+2
        })}>改变state值</button>
        <p>------------******-------------</p>
        <input type="text" ref={inp}/>
    </div>
}